#include "FilePathChoiceBox.h"

#include <QFileDialog>
#include <QStyle>

FilePathChoiceBox::FilePathChoiceBox(QWidget *parent) : QWidget(parent)
{
	mainLayout = new QHBoxLayout(this);
	lineEdit = new QLineEdit(this);
	button = new QPushButton(this);
	mainLayout -> addWidget(lineEdit);
	mainLayout -> addWidget(button);
	setLayout(mainLayout);
	button -> setFixedSize(20, 20);

	lineEdit -> setContentsMargins(0, 0, 0, 0);
	button -> setContentsMargins(0, 0, 0, 0);
	setContentsMargins(0, 0, 0, 0);
	mainLayout -> setAlignment(Qt::AlignmentFlag::AlignCenter);

	button -> setIcon(style() -> standardIcon(QStyle::StandardPixmap::SP_DirOpenIcon));

	connect(button, SIGNAL(clicked()), this, SLOT(OnButtonPushed()));
}

FilePathChoiceBox::~FilePathChoiceBox()
{
	delete mainLayout;
	delete lineEdit;
	delete button;
}

void FilePathChoiceBox::OnButtonPushed()
{
	QString fileName = QFileDialog::getExistingDirectory(this, tr("打开目录"));
	lineEdit -> setText(fileName);
}
